let parentMapKeyByChild = new Map()

function getRootEl(el) {
    let _p = el
    let parentPath = []
    while (_p != window.document.body) {
        parentPath.unshift(_p)
        _p = _p.parentNode
    }
    return parentPath[0]
}

export default {
    logLayerRelation(parent, child) {
        parentMapKeyByChild.set(getRootEl(child), getRootEl(parent))
    },
    closeLayer(child) {
        parentMapKeyByChild.delete(getRootEl(child))
    },
    isOpenedByMeOrMyChildren(parent, el) {
        let parentRootEl = getRootEl(parent)
        let _p = parentMapKeyByChild.get(getRootEl(el))
        while (_p) {
            if (_p === parentRootEl) {
                return true
            }
            _p = parentMapKeyByChild.get(_p)
        }
        return false
    }
}